package com.xy.shardingjdbcdemo.controller;

import com.xy.shardingjdbcdemo.domain.User;
import com.xy.shardingjdbcdemo.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 谢阳
 * @version 1.0
 * @date 2023/12/22 16:44
 * @description
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @GetMapping("/list")
    public List<User> list() {
        return userService.list();
    }

    @GetMapping("/{username}")
    public boolean insert(@PathVariable("username") String username) {
        User entity = new User();
        entity.setUname(username);
        return userService.save(entity);
    }
}
